package com.caiyigo.baihua.serviceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.caiyigo.baihua.dao.ZhuanyeMapper;
import com.caiyigo.baihua.dao.ZhuanyeMapperSql;
import com.caiyigo.baihua.dto.ZhuanyeDto;
import com.caiyigo.baihua.model.Xuesheng;
import com.caiyigo.baihua.model.Zhuanye;
import com.caiyigo.baihua.model.ZhuanyeWithBLOBs;
import com.caiyigo.baihua.model.Zykm;
import com.caiyigo.baihua.service.ZhuanyeService;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

/**
 * @author Administrator
 * 
 */
@Transactional
@Service
public class ZhuanyeServiceImpl implements ZhuanyeService {
	@Resource(name = "zhuanyeMapper")
	ZhuanyeMapper zhuanyeMapper;
	@Resource(name = "zhuanyeMapperSql")
	ZhuanyeMapperSql zhuanyeMapperSql;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#deleteByPrimaryKey(java.lang.String
	 * )
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int deleteByPrimaryKey(String zyDh) {
		
		return zhuanyeMapper.deleteByPrimaryKey(zyDh);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.caiyigo.zoo.service.ZhuanyeService#insert(com.caiyigo.zoo.model.
	 * ZhuanyeWithBLOBs)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int insert(ZhuanyeWithBLOBs record) {
		int i=0;
		List<Zykm>list=new ArrayList<Zykm>();
		list.add(new Zykm(record.getZyDh()));
		i=zhuanyeMapper.insert(record);
		i=zhuanyeMapper.insertToZykm(list);
		
		return i;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#insertSelective(com.caiyigo.zoo
	 * .model.ZhuanyeWithBLOBs)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int insertSelective(ZhuanyeWithBLOBs record) {
		int i=0;
		List<Zykm>list=new ArrayList<Zykm>();
		list.add(new Zykm(record.getZyDh()));
		
		i=zhuanyeMapper.insertSelective(record);
		i=zhuanyeMapper.insertToZykm(list);
		return i;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#selectByPrimaryKey(java.lang.String
	 * )
	 */
	
	@Override
	public ZhuanyeWithBLOBs selectByPrimaryKey(String zyDh) {
		
		return zhuanyeMapper.selectByPrimaryKey(zyDh);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#updateByPrimaryKeySelective(com
	 * .caiyigo.zoo.model.ZhuanyeWithBLOBs)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int updateByPrimaryKeySelective(ZhuanyeWithBLOBs record) {
		
		return zhuanyeMapper.updateByPrimaryKeySelective(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#updateByPrimaryKeyWithBLOBs(com
	 * .caiyigo.zoo.model.ZhuanyeWithBLOBs)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int updateByPrimaryKeyWithBLOBs(ZhuanyeWithBLOBs record) {
		
		return zhuanyeMapper.updateByPrimaryKeyWithBLOBs(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.ZhuanyeService#updateByPrimaryKey(com.caiyigo
	 * .zoo.model.Zhuanye)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int updateByPrimaryKey(Zhuanye record) {
		
		return zhuanyeMapper.updateByPrimaryKey(record);
	}

	@Override
	public Map<String, Zhuanye> getAll() {
		Map<String, Zhuanye> map = new HashMap<String, Zhuanye>();

		for (Zhuanye x : zhuanyeMapper.getAll()) {
			map.put(x.getZyDh(), x);
		}
		return map;
	}

	@Override
	public List getList(Zhuanye dto, PageBounds pageBounds) {
		return zhuanyeMapperSql.getList(dto, pageBounds);
	}

	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public boolean batchUpdate(List<Zhuanye> record) {
		
		return zhuanyeMapper.batchUpdate(record) > 0;
	}

}
